{% extends "rules/base.html" %}
{% load static %}
{% load bootstrap3  %}
{% block content %}
    {% if suricata.ruleset %}
    <script language="JavaScript">

function tables_checking(source) {
    $('#id_reload').prop('checked', source.checked);
    $('#id_push').prop('checked', source.checked);
}

function table_all_toggle(source) {
    checkboxes = document.getElementsByName('check_all')[0];
    if (source.prop('checked') === false)
        checkboxes.checked = false;
}

$(document).ready(function () {
    $('#id_reload').click(function() {table_all_toggle($(this))});
    $('#id_push').click(function() {table_all_toggle($(this))});
});

    </script>
    {% endif %}
    <h2 class="title">Suricata Ruleset Actions</h2>
    {% if suricata.ruleset %}
        {% if suricata.updated_date %}
            <p>
                Suricata last updated at {{ suricata.updated_date }}
            </p>
        {% endif %}
        <form action="{% url 'suricata_update' %}" method="post">
            {% csrf_token %}
            <div class="form-group" id="update">
                <h4>
                    <label>
                        <input type="checkbox" name="check_all" onclick="tables_checking(this);" />
                        Actions
                    </label>
                </h4>
                {% bootstrap_field form.reload %}
                {% bootstrap_field form.push %}
                {% include 'rules/schedule_recurrence.html' %}
                <button type="submit" class="btn btn-primary">{% bootstrap_icon "ok" %} Apply</button>
            </div>
        </form>
    {% else %}
        <h3>
            <a href="{% url 'suricata_edit' %}">Suricata </a>
                has no ruleset. Please set it <a href="{% url 'suricata_edit' %}">here.</a>
        </h3>
    {% endif %}
{% endblock content %}
{% block sidebar %}
    <div class="panel-heading">
        <h2 class="panel-title">Suricata {{ suricata.name }}</h2>
    </div>
    <ul class="panel-body">
        <li>
            <span class="type">Ruleset:</span>
            {{ suricata.ruleset }}
        </li>
        <li>
            <span class="type">Ruleset Updated:</span>
            {{ suricata.ruleset.updated_date }}
        </li>
        <li>
            <span class="type">Last Build:</span>
            {{ suricata.updated_date }}
        </li>
    </ul>
    {% if perms.rules.configuration_edit %}
        <div class="panel-heading">
            <h2 class="panel-title">
                Action
            </h2>
        </div>
        <ul class="action panel-body">
            <li>
                <a href="{% url 'suricata_edit' %}">
                    Edit
                </a>
            </li>
        </ul>
    {% endif %}
{% endblock %}
